package cn.source.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.domain.UserArticlePoints;
import cn.source.service.IUserArticlePointsService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 用户文章积分表Controller
 *
 * @author sourcebyte.vip
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/api/points")
public class UserArticlePointsController extends BaseController
{
    @Autowired
    private IUserArticlePointsService userArticlePointsService;

    /**
     * 查询用户文章积分表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserArticlePoints userArticlePoints)
    {
        startPage();
        List<UserArticlePoints> list = userArticlePointsService.selectUserArticlePointsList(userArticlePoints);
        return getDataTable(list);
    }

    /**
     * 获取用户文章积分表详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userArticlePointsService.selectUserArticlePointsById(id));
    }

    /**
     * 新增用户文章积分表
     */
    @Log(title = "用户文章积分表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserArticlePoints userArticlePoints)
    {
        return toAjax(userArticlePointsService.insertUserArticlePoints(userArticlePoints));
    }

    /**
     * 修改用户文章积分表
     */
    @Log(title = "用户文章积分表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserArticlePoints userArticlePoints)
    {
        return toAjax(userArticlePointsService.updateUserArticlePoints(userArticlePoints));
    }

    /**
     * 删除用户文章积分表
     */
    @Log(title = "用户文章积分表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userArticlePointsService.deleteUserArticlePointsByIds(ids));
    }

    /**
     * 导出用户文章积分表列表
     */
    @Log(title = "用户文章积分表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserArticlePoints userArticlePoints)
    {
        List<UserArticlePoints> list = userArticlePointsService.selectUserArticlePointsList(userArticlePoints);
        ExcelUtil<UserArticlePoints> util = new ExcelUtil<UserArticlePoints>(UserArticlePoints.class);
        util.exportExcel(response, list, "用户文章积分表数据");
    }
}
